package com.ty.day6;

import java.io.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2023/11/29 15:22
 */
public class ObjectStreamDemo01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        冲击波 cjb = new 冲击波();
        cjb.setName("冲击波");
        cjb.setAge(24);
        cjb.setLength(4);
        FileOutputStream fos = new FileOutputStream("E:\\文件夹\\java\\1\\11\\cjb.bak");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(cjb);
        oos.close();
        fos.close();
        FileInputStream fis = new FileInputStream("E:\\文件夹\\java\\1\\11\\cjb.bak");
        ObjectInputStream ois = new ObjectInputStream(fis);
        Object o = ois.readObject();
        if (o.getClass() == 冲击波.class) {
            冲击波 c = (冲击波) o;
            System.out.println(o);
        }
        ois.close();
        fis.close();
    }
}

class 冲击波 implements Serializable{
    private String name;
    private Integer age;
    private transient Integer length;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "冲击波{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", length=" + length +
                '}';
    }
}
